//
//  AppListViewController.m
//  OneWordNew
//
//  Created by qianfeng on 15-7-2.
//  Copyright (c) 2015年 朱共营. All rights reserved.
//

#import "AppListViewController.h"
#import "RootViewController.h"
#import "MyPageViewController.h"
@interface AppListViewController ()

@end

@implementation AppListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self shouUI];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(addClick) name:@"getOut" object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(addClick) name:@"secendOut" object:nil];
   
}
-(void)addClick{
    [self shouUI];
}



- (void)shouUI{
    NSArray *title=@[@"最新",@"最热",@"发现",@"我的"];
    NSMutableArray *className= [NSMutableArray arrayWithObjects:@"TimeViewController",@"ShibaoViewController",@"GlobleViewController",@"MySetViewController", nil] ;
    NSArray *picArr=@[@"latestImage1",@"hotestImage1",@"findImage1",@"myImage1"];
    NSArray *selArr=@[@"latestImage2",@"hotestImage2",@"findImage2",@"myImage2"];
    NSMutableArray *arr=[NSMutableArray array];
    for (NSInteger i=0; i<title.count; i++) {
        
        
        if (i==3) {
            
            NSString *token=[[NSUserDefaults standardUserDefaults] objectForKey:@"token"];
            NSString *name=[[NSUserDefaults standardUserDefaults] objectForKey:@"nickname"];
            NSString *boo=[[NSUserDefaults standardUserDefaults] objectForKey:@"bool"];
            NSLog(@"%ld",boo.integerValue);
            if (token.length>1&&name.length>0) {
               
                
               [className replaceObjectAtIndex:3 withObject:@"MyPageViewController"];
            }
//            if (boo.integerValue) {
//            [className replaceObjectAtIndex:3 withObject:@"MySetViewController"];
//            }
            
        }
        
 NSLog(@"%@",className[3]);
        Class vcClass=NSClassFromString(className[i]);
        RootViewController *vc=[[vcClass alloc] init];
        vc.title=title[i];
        
        
        UINavigationController *nav=[[UINavigationController alloc] initWithRootViewController:vc];
        nav.tabBarItem.image=[[UIImage imageNamed:picArr[i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        nav.tabBarItem.selectedImage=[[UIImage imageNamed:selArr[i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        if (i==3) {
            [self.navigationController setNavigationBarHidden:YES];
        }
        
        
        [arr addObject:nav];
        
    }
    self.viewControllers =arr;

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)dealloc{
    
    [[NSNotificationCenter defaultCenter]removeObserver:self];

}
/*
#pragma mark - Navigation
     
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/




@end
